package servlet.area;

import bean.Area;
import dao.AreaDao;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * Created by young on 2017/6/26.
 */
@WebServlet(name = "UpdateArea", urlPatterns = "/updateArea")
public class UpdateArea extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        response.setHeader("content-type", "text/html;charset=UTF-8");
        Area area = new Area();
        area.setId(Integer.parseInt(request.getParameter("areaId")));
        area.setName(request.getParameter("areaName"));
        AreaDao areaDao = new AreaDao();
        int row = areaDao.updateArea(area);
        if (row != 0) {
            response.sendRedirect("/areaManager.jsp");
        } else {
            response.sendRedirect("/errorPage.jsp");
        }
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }
}
